package org.ruanjj.springconvert;

public class Solution1 {
    public String convert(String s, int numRows){
        int n = s.length();
        if(n == 1 || n <= numRows || numRows == 1){
            return  s;
        }

        StringBuilder[] sb = new StringBuilder[numRows];

        for(int i = 0; i < numRows; i++){
            sb[i] = new StringBuilder();
        }

        for(int i=0,x=0; i < n; i++){
            sb[x].append(s.charAt(i));
            if(i/numRows%2 == 0){
               x++;
            }else{
                x--;
            }
        }

        StringBuilder res = new StringBuilder();
        for(int i = 0; i < numRows; i++){
            res.append(sb[i]);
        }

        return res.toString();
    }
}
